﻿using System;
using System.Data;

namespace NetFramework.DataAccess.EntityBuilder
{
    internal class DataReaderDataSource : IDataSource
    {
        private IDataReader dataReader;
        private int columnCount;

        public DataReaderDataSource(IDataReader dataReader)
        {
            this.dataReader = dataReader;
            this.columnCount = this.dataReader.FieldCount;
        }

        #region IDataSource Members

        public object this[string columnName]
        {
            get { return this.dataReader[columnName]; }
        }

        public object this[int columnIndex]
        {
            get { return this.dataReader[columnIndex]; }
        }

        public int ColumnCount
        {
            get { return this.columnCount; }
        }

        public string GetName(int index)
        {
            return this.dataReader.GetName(index);
        }

        public Type GetColumnType(int index)
        {
            return this.dataReader.GetFieldType(index);
        }
        #endregion
    }
}
